package com.gxa.hotel.sso.controller;


import com.gxa.hotel.core.common.JsonResult;
import com.gxa.hotel.sso.service.SmsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Pattern;
import java.util.Map;


@RestController
@Validated
public class SmsController {
    @Autowired
    SmsService smsService;
    @PostMapping(value = "/sms")
    @ApiOperation(value = "发送一键登录短信", notes = "发送一键登录短信", httpMethod = "POST")
    public Map sendLoginSms(
            @RequestParam
            @Pattern(regexp = "^[1](([3][0-9])|([4][5,7,9])|([5][0-9])|([6][6])|([7][3,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$",message = "格式不正确")
                    String phone) throws Exception {

        smsService.sendLoginSms(phone);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("发送成功");
        return jsonResult.getMap();
    }
}
